$(document).ready(function () {
    $.get("/ShenBlue/imp/User_Msg_Json", function (data) {
        if (IsEmpty(data.name)) {
            window.location.assign("/userInfoService/updateUserInfo.html");
        }
    });
    $("#header").load("Nav.html #Nav", function () {
        element.init();
        $("#CreditCard").addClass("layui-this");
    });
    laydate.render({
        elem: '#test1' //指定元素
        , format: 'yyyy-MM-dd'
        , value: new Date()
        , min: 0
    });
    $.get("/ShenBlue/imp/Bank_Catalog_Json", function (data) {
        console.log(data);
        const size = data.length;
        let i = 0;
        for (; i < size; i++) {
            const item = data[i];
            $("#Bank").append("<option value=\"" + item.id + "\">" + item.name + "</option>");
        }
        form.render('select');
    });
    const url = location.search.match(/id=\d+/).toString().replace('id=', '');
    $.get("/ShenBlue/imp/CreditCard_item_Json?id=" + url, function (data) {
        console.log(data);
        $("#card_id").val(data.id);
        $("#Card_num").val(data.card_id);
        $("#test1").val(data.time);
        $("#Bank").find("option[value = '" + data.bank_name + "']").attr("selected", "true");
        form.render('select');
    });

});

function Modify_CreditCard() {
    const card_id = $("#card_id").val();
    const time = $("#test1").val();
    const bank_id = $("#Bank option:selected").val();
    if (IsEmpty(card_id, time, bank_id)) {
        layer.msg("当前不能为空", {icon: 5});
        return;
    }
    $.post("/ShenBlue/imp/CreditCardInc", {mode: 2, id: card_id, time: time, bank_id: bank_id}, function (data) {
        const error = data["error"];
        const msg = data["msg"];
        if (error !== undefined) {
            layer.msg(error, {icon: 5});
            setTimeout("location.assign('/ShenBlue/userInfoService/creditCardService.html')", 1500);
            return;
        }
        layer.msg(msg, {icon: 1});
        setTimeout("location.assign('/ShenBlue/userInfoService/creditCardService.html')", 1500);
        return;
    });
}